package com.ruoyi.dgdData.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgdData.domain.pad.DataDgdModifyQyl;
import com.ruoyi.dgdData.domain.pad.DataDgdModifyZhdl;
import com.ruoyi.dgdData.domain.pad.DgdTaskReqDTO;
import com.ruoyi.dgdData.domain.report.DgdReportData;
import com.ruoyi.dgdData.service.IDataDgdQylService;
import com.ruoyi.dgdData.service.IDataDgdService;
import com.ruoyi.dgdData.service.IDataDgdZhdlService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutionException;

/**
 * 单轨吊-测试Controller
 * 
 * @author lgq
 * @date 2023-1-2
 */
@RestController
@RequestMapping("/dgdData/all")
@Api(value="单轨吊-测试",tags = "单轨吊-测试接口")
public class DataDgdController extends BaseController
{

    @Autowired
    public IDataDgdService dataDgdService;

    @Autowired
    public IDataDgdQylService dataDgdQylService;

    @Autowired
    public IDataDgdZhdlService dataDgdZhdlService;

    /**
     * 查询此单轨吊任务的所有测试项目数据
     */
    @PreAuthorize("@ss.hasPermi('dgdData:task:query')")
    @GetMapping("/{dataTaskId}")
    @ApiOperation(value="查询此单轨吊任务的所有测试项目数据")
    @ApiImplicitParam(paramType="query", name = "dataTaskId", value = "任务id", required = true, dataType = "Long")
    public AjaxResult getDetailDgd(@PathVariable("dataTaskId") Long dataTaskId) throws InterruptedException, ExecutionException {
        DgdTaskReqDTO dgdTaskReqDTO = dataDgdService.getDetailDgd(dataTaskId);
        return AjaxResult.success(dgdTaskReqDTO);
    }


    /**
     * 根据任务id删除整条单轨吊测试结果
     */
    @PreAuthorize("@ss.hasPermi('dgdData:task:remove')")
    @Log(title = "根据任务id删除整条单轨吊测试结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/updateDataDgdByDataTaskId/{dataTaskId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "dataTaskId", value = "任务id", required = true, dataType = "Long"),
    })
    @ApiOperation(value="根据任务id删除整条单轨吊测试结果")
    public AjaxResult updateDataDgdByDataTaskId(@PathVariable("dataTaskId")Long dataTaskId)
    {
        return toAjax(dataDgdService.delAllDgdData(dataTaskId));
    }

    /**
     * 保存的单轨吊数据导入报告
     */
    @PreAuthorize("@ss.hasPermi('dgdData:import:query')")
    @PostMapping("/dataDgdImportReport")
    @ApiOperation(value="保存的单轨吊数据导入报告")
    public AjaxResult dataTfjImportReport(@ApiParam(name="测试项目结果数据",value="传入json格式",required=true)@RequestBody DgdReportData dgdReportReqDTO){
        return AjaxResult.success(dataDgdService.dataDgdImportReport(dgdReportReqDTO));
    }

    /**
     * 计算平均牵引力和差值
     *
     * @param dataDgdModifyQyl
     */
    @PostMapping("/dataDgdQylModify")
    @ApiOperation(value="修改单轨吊牵引力")
    public AjaxResult modifyQyl(@ApiParam(name="单轨吊牵引力修改值",value="传入json格式",required=true)@RequestBody DataDgdModifyQyl dataDgdModifyQyl) {
        return AjaxResult.success(dataDgdQylService.modifyQyl(dataDgdModifyQyl));
    }

    /**
     * 计算最大制动力和比值
     *
     * @param dataDgdModifyZhdl
     */
    @PostMapping("/dataDgdZhdlModify")
    @ApiOperation(value="修改单轨吊制动力")
    public AjaxResult modifyZhdl(@ApiParam(name="修改单轨吊制动力",value="传入json格式",required=true)@RequestBody DataDgdModifyZhdl dataDgdModifyZhdl) {
        return AjaxResult.success(dataDgdZhdlService.modifyZhdl(dataDgdModifyZhdl));
    }
}
